package me.wangxuan.pat;
import java.io.IOException;
import java.util.logging.FileHandler;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;
public class LogTest {
	private static final Logger logger = Logger.getLogger(LogTest.class.getName());
	public static void main(String[] args) {
		try {
            // 创建 FileHandler 实例，指定日志文件的路径
            FileHandler fileHandler = new FileHandler("app.log", true);

            // 设置日志格式为简单格式
            SimpleFormatter formatter = new SimpleFormatter();
            fileHandler.setFormatter(formatter);

            // 将 FileHandler 添加到 Logger
            logger.addHandler(fileHandler);

            // 记录不同级别的日志信息
            logger.info("This is an info message.");
            logger.warning("This is a warning message.");
            logger.severe("This is a severe message.");

        } catch (IOException e) {
            logger.severe("Failed to create log file: " + e.getMessage());
        }

	}

}
